//index.js
//获取应用实例
import { api } from '../../utils/config';
const app = getApp();
let page = 1;//初始页面
Page({
  data: {
    wuhan: '武汉',
    imgUrls: [],
    productList: [],
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 500,
    indicatorActiveColor: "#da1a1e",//当前选中的指示点颜色
    indicatorColor: "rgba(255, 255, 255, .9)"//指示点颜色

  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  //拼团介绍页面跳转
  checkIntroduce: function () {
    wx.navigateTo({
      url: '../introduce/introduce'
    })
  },
  onLoad: function () {
    let that = this
    app.getUserInfo()
    // let url = api + "/api/fg/cityList";
    // app.httpClient.post(url).then(res => {
    //   let cityAreaId = res.data.obj.cityKtList[0].cityAreaId;
    //   if(!that.data.wuhan) {
    //     that.setData({
    //       wuhan: res.data.obj.cityKtList[0].cityName
    //     })
    //   }
    //   wx.setStorage({
    //     key: "cityAreaId",
    //     data: cityAreaId
    //   })
    // })
    wx.getStorage({
      key: 'cityInfo',
      success: function (res) {
        that.setData({ wuhan: res.data.cityName })
        let datas = {
          areaId: res.data.areaId,
          sord: 'desc',
          page: page,
          rows: 15,
        }
        let url = api + "/api/fg/index";
        app.httpClient.post(url,datas).then(res => {
          let bannerList = res.data.obj.bannerList;
          let fgList = res.data.obj.fgList.rows;
          let status = res.data.obj.fgList.rows.status;
          // console.log(fgList);
          that.setData({
            imgUrls: bannerList,
            productList: fgList
          })
        })
      }
    }) 
  },
  onShow: function() {
    
  },
  onReachBottom: function () {
    let that = this;
    console.log('上拉');
    page++;
    console.log(page);
    wx.getStorage({
      key: 'cityAreaId',
      success: function (res) {
        let cityAreaId = console.log(res.data);
        let datas = {
          areaId: res.data,
          sord: 'desc',
          page: page,
          rows: 15,
        }
        let url = api + "/api/fg/index";
        app.httpClient.post(url).then(res => {
          let bannerList = res.data.obj.bannerList;
          let fgList = res.data.obj.fgList.rows;
          // console.log(fgList);
          that.setData({
            productList: fgList.concat(fgList)
          })
        })
      }
    })
  },
  onPullDownRefresh: function () {
    console.log('下拉')
  },
})
